/**
 * 非组合促销活动 - 修改失效日期及备注页面
 * @author miaoyl
 * @date 2019/03/05
 */
define(function () {

    var self,
        app = win.app,
        doc = document,
        layui = win.layui,
        vueData = {
            form: '',
            rules: {
                GWDC009: [
                    {required: true, message: '不可为空', trigger: 'blur'}
                ],
                GWDC010: [
                    {required: true, message: '不可为空', trigger: 'blur'}
                ],
                GWDC003: [
                    {required: true, message: '不可为空', trigger: 'blur'}
                ],
                GWDC004: [
                    {required: true, message: '不可为空', trigger: 'blur'}
                ],
                GWDC005: [
                    {required: true, message: '不可为空', trigger: 'blur'}
                ],
                GWDC007: [
                    {required: true, message: '不可为空', trigger: 'blur'}
                ]
            },
            selectOptions: {
                crm_gwcd_gwcd005: app.datas_("crm_gwcd_gwcd005"),
                crm_gwcd_gwcd006: app.datas_("crm_gwcd_gwcd006"),
                crm_gwcd_gwcd007: app.datas_("crm_gwcd_gwcd007")
            }
        },
        cols1 = [[
            {type: 'checkbox', title: '选择'},
            {field: 'GWDC002',width: 80, title: '项序'}
            , {field: 'GWDC016', width: 80, title: '客户编号'}
            , {field: 'GWDC017', width: 100, title: '客户名称'}
            , {field: 'GWDC018', width: 140, title: '品号'}
            , {field: 'GWAML003', width: 160, title: '品名'}
            , {field: 'GWAML004', width: 80, title: '规格'}
            , {field: 'GWDC019', width: 80, title: '单位说明'}
            , {field: 'GWDC020', width: 80, title: '起订数量'}
            , {field: 'GWDC021', width: 80, title: '起订金额'}
            , {field: 'GWDC022', width: 80, title: '阶梯定价'}
            , {field: 'GWDC023', width: 80, title: '结算价'}
            , {field: 'GWDC024', width: 80, title: '活动价格'}
            , {field: 'GWDC025', width: 140, title: '最大赠品金额'}
            , {field: 'GWDC026', width: 140, title: '最大赠品数量'}
        ]],
        cols2 = [[
            {type: 'checkbox', title: '选择'}
            , {field: 'GWDCZ002', width: 80, title: '项序'}
            , {field: 'GWDCZ003', width: 80, title: '序号'}
            , {field: 'GWDCZ004', width: 140, title: '赠品品号'}
            , {field: 'GWAML003', width: 160, title: '赠品品名'}
            , {field: 'GWAML004', width: 100, title: '赠品规格'}
            , {field: 'GWDCZ005', width: 80, title: '赠品价格'}
            , {field: 'GWDCZ006', width: 80, title: '结算价',hide:true}
        ]],
        callObj,
        listData1 = null,
        listData2 = null,
        table_select_data = [],
        table,
        gwdc003Table1,
        gwdc003Table2
    ;

    var Gwdc003EditGwdc010 = app.Module.extend({
            init: function () {
                self = this;
                self._super({
                    _tag: 'gwdc003_edit_gwdc010'
                }, win);
            },

            initTable1: function () {//商品信息表
                layui.use(['table'], function () {
                    table = layui.table;
                    gwdc003Table1 = table.render({
                        elem: app.getByid(doc, 'gwdc003_edit_gwdc010_table1'),
                        id: 'gwdc003_edit_gwdc010_table1',
                        cols: cols1,
                        height:'200',
                        page: false,
                    });

                });
            },

            initTable2: function () {//商品信息表
                layui.use(['table'], function () {
                    table = layui.table;
                    gwdc003Table2 = table.render({
                        elem: app.getByid(doc, 'gwdc003_edit_gwdc010_table2'),
                        id: 'gwdc003_edit_gwdc010_table2',
                        cols: cols2,
                        height:'200',
                        page: false
                    });

                });
            },

            table1Reload: function () {
                gwdc003Table1.reload({data: listData1});
            },

            table2Reload: function () {
                gwdc003Table2.reload({data: listData2});
            },

            editAllData: function () {
                app.ajax({
                    xurl: 'crm/gwdc003/editGwdc010',
                    xdata: vueData.form,
                    loading: true,
                    okmsg: self._moduleName + '修改成功',
                    cb: function (result) {
                        if (result.ok) {
                            app.pageModule('gwdc003').reloadTableCurr();
                            self._closeTpl();
                        }
                    }
                });
            },

            _call: function (tagData) {
                callObj = tagData.obj;
                app.extendUpLow({
                    target: vueData.form,
                    res: callObj.data[0],
                    reset: true
                });
                app.ajax({
                    xurl: 'crm/gwdc003/getGwdcData',
                    xdata: {GWDC001: callObj.data[0].GWDC001},
                    loading: true,
                    cb: function (result) {
                        listData1 = result.data.data;
                        self.table1Reload();
                    }
                });
                app.ajax({
                    xurl: 'crm/gwdc003/getGwdczData',
                    xdata: {GWDC001: callObj.data[0].GWDC001},
                    loading: true,
                    cb: function (result) {
                        listData2 = result.data.data;
                        self.table2Reload();
                    }
                });
            },

            _ready: function () {
                table = layui.table;
                vueData.form = app.fields_(['crm_gwdc']);
                var vue = new Vue({
                    el: '#gwdc003_edit_gwdc010',
                    data: vueData,
                    watch: {},
                    methods: {
                        cancle: function () {
                            self._closeTpl();
                        },
                        saveData: function () {
                            this.$refs['form'].validate(function (valid) {
                                if (valid) {
                                    if(vueData.form.GWDC009 > vueData.form.GWDC010){
                                        app.showError("失效日期不可小于生效日期！");
                                        return;
                                    }
                                    self.editAllData();
                                }
                            });
                        }
                    },
                    created: function () {
                        self._setEleIsReady('gwdc003_edit_gwdc010');
                    }
                });

                self.initTable1();
                self.initTable2();
            },
            _lazy: function () {
                this._super();
            }
        })
    ;

    return new Gwdc003EditGwdc010();

})
;